package com.zsrt.devbase.common.utils.mail;

import com.zsrt.devbase.common.utils.MailConstantDefine;

/** 
 * 采用builder模式控制参数，放弃set方法设置参数
 * @author leixin  
 * @Email leixin821792669@gmail.com
 * @date 2018年7月7日 下午9:07:03
 * @version 1.0
 */
public class MailConfig {

	//必填参数
	private final String formAddr;
	private final String hostName ;
	private final Integer smtpPort ;
	//选填参数
	private String password;
	private String formName;
	private Boolean sslOnConnect;
	private String charSet;

	public static class MailConfigBuilder{
		private final String formAddr;
		private final String hostName;
		private final Integer smtpPort;
		private String password;
		private String formName  = MailConstantDefine.SYSTEM_MESSAGE;
		private Boolean sslOnConnect  = Boolean.TRUE;
		private String charSet  = MailConstantDefine.DEFAULT_CHARSET;
		public MailConfigBuilder(String formAddr) {
			this(formAddr,MailConstantDefine.DEFAULT_HOST_NAME);
		}
		public MailConfigBuilder(String formAddr,String hostName) {
			this(formAddr,hostName,MailConstantDefine.DEFAULT_SMTP_PORT);
		}
		public MailConfigBuilder(String formAddr,Integer smtpPort) {
			this(formAddr,MailConstantDefine.DEFAULT_HOST_NAME,smtpPort);
		}
		public MailConfigBuilder(String formAddr,String hostName,Integer smtpPort) {
			super();
			this.formAddr = formAddr;
			this.hostName = hostName;
			this.smtpPort = smtpPort;
		}
		public MailConfigBuilder password(String password) {
			this.password = password;
			return this;
		}
		
		public MailConfigBuilder formName(String formName) {
			this.formName = formName;
			return this;
		}
		public MailConfigBuilder sslOnConnect(Boolean sslOnConnect) {
			this.sslOnConnect = sslOnConnect;
			return this;
		}
		public MailConfigBuilder charSet(String charSet) {
			this.charSet = charSet;
			return this;
		}
		
		public MailConfig build() {
			return new MailConfig(this);
			
		}
	}
	private MailConfig (MailConfigBuilder builder) {
		this.formAddr = builder.formAddr;
		this.hostName = builder.hostName;
		this.formName = builder.formName;
		this.password = builder.password;
		this.smtpPort = builder.smtpPort;
		this.sslOnConnect = builder.sslOnConnect;
		this.charSet = builder.charSet;
	}
	public String getFormAddr() {
		return formAddr;
	}
	public String getHostName() {
		return hostName;
	}
	public Integer getSmtpPort() {
		return smtpPort;
	}
	public String getPassword() {
		return password;
	}
	public String getFormName() {
		return formName;
	}
	public Boolean getSslOnConnect() {
		return sslOnConnect;
	}
	public String getCharSet() {
		return charSet;
	}
	public void setFormName(String formName) {
		this.formName = formName;
	}
	public void setSslOnConnect(Boolean sslOnConnect) {
		this.sslOnConnect = sslOnConnect;
	}
	public void setCharSet(String charSet) {
		this.charSet = charSet;
	}
	
}
